{extend name="main"}
{block name="style"}
{css href="__TEMPLATE_STATIC__/user.css"}
{/block}
{block name="header"}
{include file="module/user_top_nav"/}
{/block}
{block name="body"}
<div class="flex1 flex h-100">
	<div class="w-180px nav-left p-4 overflow-y-auto">
	{include file="module/user/personal_left"/}
	</div>
	<div class="frame-body flex-1 overflow-y-auto py-3">
		<div class="container-xl bg-white shadow">
			<el-tabs v-model="activeName">
				<el-tab-pane label="职位收藏夹" name="follow_jobs"></el-tab-pane>
				<el-tab-pane label="关注的企业" name="follow_company"></el-tab-pane>
			</el-tabs>
			<div class="bg-1E54E5 p-3 my-3 flex">
				<div><i class="el-icon-warning h3 mb-0 text-primary"></i></div>
				<div class="flex-1 pl-2">
					<h6 class="text-primary">小提示</h6>
					<div class="text-secondary">招聘过程中企业无权收取任何费用，避免上当受骗！</div>
				</div>
			</div>
			<div class="pb-3" v-if="activeName!='follow_company'">
				<el-button-group class="text-nowrap">
				  <el-button type="primary" size="mini">批量投递</el-button>
				  <el-button type="info" size="mini">取消收藏</el-button>
				</el-button-group>
			</div>
			<div class="table-responsive">
				<el-table
					ref="multipleTable"
			      	:data="tableData"
		    		stripe
		    		v-loading="search.ajax"
		    		style="width: 100%;"
		    		header-cell-class-name="bg-1E54E5 text-666666">
			      <el-table-column
			        prop="title"
			        label="职位名称"
			        width="180"
			        v-if="activeName!='follow_company'">
			      </el-table-column>
			      <el-table-column
			        prop="company_name"
			        label="公司名称"
			        min-width="180"
			        show-overflow-tooltip>
			      </el-table-column>
			      <el-table-column
			        label="在招职位"
			        width="120"
			        v-if="activeName!='follow_jobs'">
			        <template slot-scope="scope">
			        	<el-link :href="'/company/'+scope.row.company_id+'.html'" type="primary" target="_blank" :underline="false">{{scope.row.jobs_sum}}</el-link>
			        </template>
			      </el-table-column>
			      <el-table-column
			        prop="create_time"
			        label="时间"
			        show-overflow-tooltip>
			      </el-table-column>
			      <el-table-column
			        label="职位状态"
			        width="80"
			        v-if="activeName!='follow_company'">
			        <template slot-scope="scope">
			        	<span class="small text-success" v-if="scope.row.status === 1">在招</span>
			        	<span class="small text-secondary" v-if="scope.row.status === 0">停止招聘</span>
			        	<span class="small text-secondary" v-if="scope.row.status === 2">已删除</span>
			        </template>
			      </el-table-column>
			      <el-table-column
			        label="操作"
			        width="140">
			        <template slot-scope="scope">
			        	<el-button-group class="text-nowrap">
						  <el-button type="info" size="minism" v-if="scope.row.is_delivery && activeName!='follow_company'">已投递</el-button>
						  <el-button type="primary" size="minism" v-if="!scope.row.is_delivery && activeName!='follow_company'" @click="deliveryResume(scope.row)">投递</el-button>
						  <el-button type="info" size="minism" @click="toggleCollection(scope.row,scope.$index);">取消收藏</el-button>
						</el-button-group>
			        </template>
			      </el-table-column>
			    </el-table>
			</div>
			<div class="py-3" v-if="activeName!='follow_company'">
				<el-button-group class="text-nowrap">
				  <el-button type="primary" size="mini">批量投递</el-button>
				  <el-button type="info" size="mini">取消收藏</el-button>
				</el-button-group>
			</div>
			<div class="table-responsive py-3">
				<el-pagination
				  background
				  :hide-on-single-page="true"
				  @current-change="setPageChange"
			      :current-page="search.page"
			      :page-size="15"
			      layout="total,  prev, pager, next, jumper"
			      :total="search.total">
			    </el-pagination>
			</div>
		</div>
	</div>
</div>
{/block}
{block name="footer"}
{include file="module/login"/}
{/block}
{block name="script"}
<script type="text/javascript">
	var vm=new Vue({
		el:'#app',
		data:{
			view:XYBase.view,
			userInfo:UserInfo,
			loginTabs:XYBase.loginTabs,
			feedback:XYBase.feedback,
			activeName:'follow_jobs',
			confirm:0,
			search:{
				status:'follow_jobs',
		    	ajax:false,
				total:0,
				page: 1
			},
			tableData:[]
		},
		watch:{
		    view:XYBase.viewWatch,
		    loginTabs:XYBase.loginTabsWatch,
		    activeName(val,oldVal){
		    	this.search.status=val;
				this.search.page=1;
				this.initHtml();
		    },
			userInfo:{
				handler(val,oldVal){
					if (!val.id) {
						window.location.reload();
					}
				},
				deep:true
			},
		},
		created(){
			XYBase.created(this);
			this.initHtml();
		},
		methods:XYBase.methods({
			toggleSelection(rows) {
				if (rows) {
				  rows.forEach(row => {
				    this.$refs.multipleTable.toggleRowSelection(row);
				  });
				} else {
				  this.$refs.multipleTable.clearSelection();
				}
			},
			handleSelectionChange(val) {
				this.multipleSelection = val;
			},
			filterHandler(value, row, column){
				console.log(value);
		        const property = column['property'];
		        return row[property] === value;
			},
			toggleCollection(row,index){
				var _this=this;
				var url='/jobs/toggleJobsCollection/'+row.jobs_id;
				if (_this.search.status=='follow_company') {
					url='/company/toggleCompanyCollection/'+row.company_id
				}
				_this.$confirm('确定要取消关注吗？', '提示', {
					dangerouslyUseHTMLString:true,
		          	confirmButtonText: '确定',
		          	cancelButtonText: '取消',
		          	type: 'warning'
		        }).then(() => {
		        	_this.sendGet({
		        		url:url
		        	},function(ret){
		        		if (ret) {
		        			if (ret.code === 0) {
								_this.tableData.splice(index,1);
		        			}else{
		        				XYBase.msg(ret.msg);
		        			}
		        		}
		        	});
		        }).catch(() => {
		        	XYBase.msg('已取消');
		        });
			},
			setPageChange(val){
				this.search.page=val;
				this.initHtml();
			},
			initHtml(){
				var _this=this;
				_this.search.ajax=true;
				_this.sendGet({
					url:'',
					data:_this.search,
				},function(ret){
					_this.search.ajax=false;
					if (ret) {
						_this.tableData=[];
						_this.search.total=ret.data.total;
						if (ret.code === 0) {
							_this.search.page++;
							_this.tableData=ret.data.data;
						}else XYBase.msg(ret.msg);
					}
				});
			}
		})
	});
</script>
{/block}